package com.apes.scm.masterdata.car.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 车型服务等级
 * 〈CarModelServiceLevel〉
 *
 * @author weisj
 * @create 2018-07-30
 * @since 1.0.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CarModelServiceLevel.CONST_TABLE_NAME, indexes = {
        @Index(name = "u_mas_carmodel_service_level", columnList = "car_model_id", unique = true)
})
public class CarModelServiceLevel extends Model {
    public static final String CONST_TABLE_NAME = "mas_carmodel_service_level";

    @Id
    @Column(name = "id", length = 60)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "车型服务等级编码")//自动生成编码
    @Comment("编码")
    private String id;//车型服务等级编码

//    @Column(name = "name",length = 120)
//    @Comment("名称")
//    private String name;//车型服务等级名称

    @Column(name = "maintenance_mileage", length = 20)
    @Comment("保养间隔里程")
    private int maintenanceMileage;//保养间隔里程

    @Column(name = "maintenance_interval",length = 20 )
    @Comment("保养间隔时间")
    private int maintenanceInterval;//保养间隔时间

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_service_level_id",referencedColumnName = "id")
    @Comment("车辆服务等级")
    private CarServiceLevel carServiceLevel;//车辆服务等级

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_model_id",referencedColumnName = "id")
    @Comment("车型")
    private CarModel carModel;//车型
}
